#!/bin/bash

function install_development() {
  sudo yum install -y wget tar git -y
  source /etc/profile
}


function install_PAIRADISE() {
  echo "# PAIRADISE正在下载"
  echo "$1"
  echo -e "\033[1;32;1m# PAIRADISE 依赖开始安装\033[0m"
  Rscript "$1"/install-R-deps.R 
  echo -e "\033[1;32;1m# PAIRADISE 依赖安装成功\033[0m"
  cd "$1"
  git clone https://github.com/Xinglab/PAIRADISE.git
  if [[ $? -eq 0 ]]; then
    echo -e "\033[1;32;1m# PAIRADISE 已经下载成功\033[0m"
  else
    echo -e "\033[31m# PAIRADISE 下载失败,请重新执行脚本\033[0m"
    exit 1
  fi

  echo -e "\033[1;32;1m# PAIRADISE 开始安装\033[0m"
  cd "$1"/PAIRADISE/pairadise
  chmod +x configure
  ./configure CXX=clang++
  make && make install
  echo -e "\033[1;32;1m# PAIRADISE 安装成功\033[0m" 
  rm -rf "$1"/PAIRADISE
}

function main() {
  set -e
  install_development
  install_PAIRADISE "$1"
}

main "$@"
